﻿#ifndef UIBASEDIALOG_H
#define UIBASEDIALOG_H

#include <QDialog>

QT_BEGIN_NAMESPACE
namespace Ui
{
    class UiBaseDialog;
}
QT_END_NAMESPACE

/// @brief 基础对话框
/// 用于为当前项目提供公共的一个基础对话框类,
/// 它是许多其他类的基类, 为不同类提供共通的功能.
///
class UiBaseDialog: public QDialog
{
    Q_OBJECT

protected:
    Ui::UiBaseDialog* m_ui;

private:
    QPoint m_start; // 记录鼠标按下时的初始位置, 用于拖动对话框
    int m_sz = 25;  // 按钮的默认大小

public:
    UiBaseDialog(QWidget* parent = nullptr);
    ~UiBaseDialog();

    void setTitle(const QString& title);
    void setLogo(const QString& path);
    void addMinButton(const QString& path, const QString& hoverPath);
    void addMaxButton(
            const QString& maxPath,
            const QString& maxPathHover,
            const QString& normalPath,
            const QString& normalPathHover);
    QPushButton* addButton(const QString& path, const QString& hoverPath);
    void setButtonImage(
            QPushButton* btn,
            const QString& path,
            const QString& hoverPath);
    void setAllButtonSize(int w = 20);
    void setKeyDisabled();
    void addTitleLine(int w = 2);

protected:
    void mousePressEvent(QMouseEvent* event);
    void mouseMoveEvent(QMouseEvent* event);
    bool eventFilter(QObject* obj, QEvent* event);
    QWidget* body();

private:
    void addCloseButton(const QString& path, const QString& hoverPath);
    void addWidget(QWidget* w);
};
#endif // UIBASEDIALOG_H
